package com.wuheng.smartlock;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.os.Handler;

public class PsensorListener implements SensorEventListener {
	private boolean state = false;
	private int tapCount = 0;
	private boolean isOk = false;

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		// TODO 自动生成的方法存根
		state = event.values[0] == 0;
		// if (state) {
		mHandler.removeMessages(0);
		if (isOk)
			tapCount++;
		else
			tapCount = 0;
		// Log.d("wuheng", " tapCount = " + tapCount);
		mHandler.sendEmptyMessageDelayed(0, 2000);
		// }

	}

	public void setOk(boolean ok) {
		isOk = ok;
	}

	public boolean getState() {
		return state;
	}

	public int getTapCount() {
		return tapCount;
	}

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 0:
				tapCount = 0;
				break;
			}
		};
	};

}
